//
//  MSWeaponManager.m
//  MagicSword
//
//  Created by Netease on 15/11/19.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSWeaponManager.h"
#import "MSDBManager.h"

@implementation MSWeaponManager

+ (id)shareManager {
    static MSWeaponManager *weaponMgr = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        weaponMgr = [[MSWeaponManager alloc] init];
    });
    return weaponMgr;
}

- (id)init {
    self = [super init];
    if (self) {
        [self initStoreWeapon];
    }
    return self;
}

- (void)initStoreWeapon {
    _storeWeaponArray = [NSMutableArray array];
    [_storeWeaponArray setArray:[[MSDBManager shareManager] getDBStoreWeaponArray]];

//    [_storeWeaponArray addObject:[MSWeaponManager createWeaponWithModel:MSWeaponModel_A]];
//    [_storeWeaponArray addObject:[MSWeaponManager createWeaponWithModel:MSWeaponModel_B]];
//    [_storeWeaponArray addObject:[MSWeaponManager createWeaponWithModel:MSWeaponModel_C]];
}

- (void)saveStoreWeapon {
    [[MSDBManager shareManager] saveDBStoreWeapon:_storeWeaponArray];
}
- (NSArray *)getStoreWeaponArray {
    return _storeWeaponArray;
}

// 删除仓库装备
- (BOOL)removeWeapon:(MSWeaponInfo *)weapon {
    if ([_storeWeaponArray indexOfObject:weapon] == NSNotFound) {
        return NO;
    }
    [_storeWeaponArray removeObject:weapon];
    return YES;
}
// 增加仓库装备
- (BOOL)addWeapon:(MSWeaponInfo *)weapon {
    [_storeWeaponArray addObject:weapon];
    return YES;
}

+ (MSWeaponInfo *)createWeaponWithModel:(MSWeaponModel)model {
    MSWeaponInfo *weapon = [[MSWeaponInfo alloc] init];
    weapon.name = @"";
    weapon.detailMsg = @"";
    weapon.Crit =  0;
    weapon.DoubleHit = 0;
    weapon.Vampire = 0;
    weapon.model = model;
    
    switch (model) {
        case MSWeaponModel_1:
            // 初始化内容
            weapon.name = @"木剑";
            weapon.Attack = 3;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_1";
            weapon.type = MSWeaponType_Sword;
            break;
        case MSWeaponModel_2:
            // 初始化内容
            weapon.name = @"铁剑";
            weapon.Attack = 5;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_2";
            weapon.type = MSWeaponType_Sword;
            break;
        case MSWeaponModel_3:
            // 初始化内容
            weapon.name = @"银剑";
            weapon.Attack = 10;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_3";
            weapon.type = MSWeaponType_Sword;
            break;
        case MSWeaponModel_4:
            // 初始化内容
            weapon.name = @"木斧";
            weapon.Attack = 3;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_4";
            weapon.type = MSWeaponType_Axe;
            break;
        case MSWeaponModel_5:
            // 初始化内容
            weapon.name = @"铁斧";
            weapon.Attack = 5;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_5";
            weapon.type = MSWeaponType_Axe;
            break;
        case MSWeaponModel_6:
            // 初始化内容
            weapon.name = @"银斧";
            weapon.Attack = 10;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_6";
            weapon.type = MSWeaponType_Axe;
            break;
        case MSWeaponModel_7:
            // 初始化内容
            weapon.name = @"木枪";
            weapon.Attack = 3;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_7";
            weapon.type = MSWeaponType_Spear;
            break;
        case MSWeaponModel_8:
            // 初始化内容
            weapon.name = @"铁枪";
            weapon.Attack = 5;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_8";
            weapon.type = MSWeaponType_Spear;
            break;
        case MSWeaponModel_9:
            // 初始化内容
            weapon.name = @"银枪";
            weapon.Attack = 10;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_9";
            weapon.type = MSWeaponType_Spear;
            break;
        case MSWeaponModel_10:
            // 初始化内容
            weapon.name = @"火法术";
            weapon.Attack = 8;
            weapon.useCount = 8;
            weapon.imageName = @"WeaponModel_10";
            weapon.type = MSWeaponType_Magic;
            break;
        case MSWeaponModel_11:
            // 初始化内容
            weapon.name = @"冰法术";
            weapon.Attack = 12;
            weapon.useCount = 8;
            weapon.imageName = @"WeaponModel_11";
            weapon.type = MSWeaponType_Magic;
            break;
        case MSWeaponModel_12:
            // 初始化内容
            weapon.name = @"雷法术";
            weapon.Attack = 18;
            weapon.useCount = 8;
            weapon.imageName = @"WeaponModel_12";
            weapon.type = MSWeaponType_Magic;
            break;
        case MSWeaponModel_13:
            // 初始化内容
            weapon.name = @"木弓";
            weapon.Attack = 5;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_13";
            weapon.type = MSWeaponType_Bow;
            break;
        case MSWeaponModel_14:
            // 初始化内容
            weapon.name = @"铁弓";
            weapon.Attack = 8;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_14";
            weapon.type = MSWeaponType_Bow;
            break;
        case MSWeaponModel_15:
            // 初始化内容
            weapon.name = @"银弓";
            weapon.Attack = 13;
            weapon.useCount = 10;
            weapon.imageName = @"WeaponModel_15";
            weapon.type = MSWeaponType_Bow;
            break;
            
        default:
            break;
    }
    
    return weapon;
}

@end
